package dreamCookGame.conveyorBeltMiniGame;
import java.awt.Point;
import java.awt.Rectangle;

import dreamCookGame.Item;

public class Bag extends Item {

	int _boxCounter;
	boolean _movingRight;
	boolean _movingLeft;
	
	public Bag(String[] bagImages, int x, int y) {
		super("bag", bagImages, x, y, null, null, null, false, null);
		
		_boxCounter = 0;
		_movingRight = false;
		_movingLeft = false;
	}
	
	public void moveRight() {
		_movingRight = true;
	}
	
	public void moveLeft() {
		_movingLeft = true;
	}
	
	public int getItemState(Point[] points) {
		Rectangle rectangle = this._itemButton._boundingBox.getBounds();
		int bagTopY = rectangle.y;
		int bagLeftX = rectangle.x;
		int bagRightX = rectangle.x + rectangle.width;
		int boxBottomY = points[0].y;
		int boxLeftX = points[0].x;
		int boxRightX = points[1].x;
		
		//if(bagTopY == boxBottomY)
		//	System.out.println("yes! they're equal at some point");

		//System.out.println("bag left: " + bagLeftX);
		//System.out.println("box right: " + bagRightX);
		
		//check if item hit floor
		if(boxBottomY >= 600 && (boxRightX < bagLeftX || boxLeftX > bagRightX)) {
			return 3;
		}
		//check if item is in bag
		else if(boxBottomY >= bagTopY && boxLeftX >= bagLeftX && boxRightX <= bagRightX) {
			return 2;
		}
		//else item still falling
		else {
			return 0;
		}
	}
	
	public void loadBox() {
		_boxCounter++;
	}

	public void stopRight() {
		_movingRight = false;
	}
	public void stopLeft() {
		_movingLeft = false;
	}

	public void shift() {

		if(_movingRight){
			this._x += 3;
			this.updatePosition(this._x, this._y);
		}
		if(_movingLeft){
			this._x -= 3;
			this.updatePosition(this._x, this._y);
		}
	}
}
